# Introduction ------------------------------------------------------------

# Project: The Effects of Independent Local Radio on Tanzanian Public Opinion: Evidence from a Planned Natural Experiment
# Authors: Donald P. Green, Dylan Groves, Constantine Manda, Beatrice Montano, Bardia Rahmani

# File: Figure 1: The Rise of Independent Radio in Tanzania since 1995
# Last updated: 2022.10

# -------------------------------------------------------------------------
  

# Packages ----------------------------------------------------------------

  pacman::p_load(extrafont,
                 ggplot2,
                 googlesheets4,
                 googledrive,
                 tidyverse,
                 xlsx)

  library(extrafont)
  loadfonts(device = "win")

# Clear -------------------------------------------------------------------

  rm(list=ls()) ## Clears all other data

# Set Working Directory ---------------------------------------------------

  setwd("X:/Dropbox/Wellspring Tanzania Papers/Wellspring Tanzania - Natural Experiment/pfm_ne_replication")

# Load Data ---------------------------------------------------------------

  df.main <- read.xlsx("pfm_ne_replication_data_radios.xlsx", 
                       sheetName = "main")
  
# Plot --------------------------------------------------------------------

  # create grouped data
  df.grouped <- df.main %>%
    group_by(year, ownership_type) %>%
    summarize(station_num = n())

  plot <- 
  ggplot(data = df.grouped, 
         aes(x = year, 
             y = station_num, 
             group = ownership_type)) +
    geom_line(aes(linetype = ownership_type), 
                color = "black",
                size = 1,
                se = FALSE) +
    geom_point(size = 3) +
    scale_y_continuous(name="Number of Stations",
                       expand = c(0, 0)) +
    scale_x_continuous(name="Year (1960-2022)",
                       limits = c(1960, 2022)) +
    geom_vline(xintercept = 1962, 
               color = "black") +
    geom_text(aes(x=1962.75, 
                  y=100,
                  angle=90,
                  label="National Independence (1962)"), 
              colour="black", 
              size = 6,
              family="serif") + 
    geom_vline(xintercept = 1993, 
               color = "black") +
    geom_text(aes(x=1993.75, 
                  y=100,
                  angle=90,
                  label="Broadcast Reform Act (1993)"), 
              colour="black", 
              size = 6,
              family="serif") + 
    geom_text(aes(x=2009, 
                  y=170,
                  label="Independently Owned Stations"), 
              colour="black", 
              size = 6,
              family="serif") + 
    geom_text(aes(x=2013, 
                  y=21,
                  label="State Owned Stations"), 
              colour="black", 
              size = 6,
              family="serif") + 
    theme_classic() +
    guides(linetype=guide_legend("Ownership Type")) +
    theme(legend.position = "none",
          text=element_text(size=18,family="serif")) 
  
  

# Save --------------------------------------------------------------------

  ggsave("pfm_ne_replication_f1_radiogrowth.png", plot = plot, 
         width = 12, height = 7.5, units = "in")  


  
  